<?php                                  
require_once("../lib/ebpls.utils.php");
define('FPDF_FONTPATH','font/');
require('../ebpls-php-lib/html2pdf_lib/fpdf.php');     
include("../lib/phpFunctions-inc.php");
include("../includes/variables.php");
include("../lib/multidbconnection.php");
                                                                                                 
$dbLink =Open($dbtype,$connecttype,$dbhost,$dbuser,$dbpass,$dbname);
$criteria="$brgy_name $owner_last $trans $cap_inv $last_yr";

//frederick this will create PDF class
class PDF extends FPDF
{
var $prov;
var $lgu;
var $office;
var $y0;
var $datef;
var $datet;

	function setDateRange($x='', $y='') {
		$this->datef = $x;
		$this->datet = $y;
//		echo 'setLGUinfo'.$this->prov;
	}
	function setLGUinfo($p='', $l='', $o='') {
		$this->prov = $p;
		$this->lgu = $l;
		$this->office = $o;
//		echo 'setLGUinfo'.$this->prov;
	}

function AcceptPageBreak()
{
    //Method accepting or not automatic page break
    if($this->y<2)
    {
        //Set ordinate to top
        $this->SetY($this->y0);
        //Keep on page
        return false;
    }
    else
    {
        return true;
    }
}
	
//Page header
	function Header()
	{
	    //Logo
	    //$this->Image('logo_pb.png',10,8,33);
	    //Arial bold 15
	
	$this->Image('../images/ebpls_logo.jpg',10,8,33);
	$this->SetFont('Arial','B',12);
	$this->Cell(340,5,'Republic of the Philippines',0,1,'C');
	$this->Cell(340,5,'Province of '.$this->prov,0,1,'C');
	$this->Cell(340,5,'MUNICIPALITY OF '.strtoupper($this->lgu),0,2,'C');
//SEE change made on lines 111 & 113
//-------------------------------------------------------------
	$this->SetFont('Arial','B',14);
	$this->Cell(340,5,$this->office,0,2,'C');
	$this->Cell(340,5,'',0,2,'C');	
	$this->SetFont('Arial','BU',16);
	$this->Cell(340,5,'LIST OF BLACKLISTED ESTABLISHMENTS',0,1,'C');
	$this->SetFont('Arial','B',12);
	$this->Cell(340,5,'From : '.$this->datef.' To : '.$this->datet,0,1,'C');
	$this->Ln(22);
	
} 	
//Page footer
	function Footer()
	{
	    //Position at 1.5 cm from bottom
	    $this->SetY(-15);
	    //Arial italic 8
	    $this->SetFont('Arial','I',8);
	    //Page number
	    $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
	}
} // end of PDF class

$result=mysql_query("select lguname, lguprovince, lguoffice from ebpls_buss_preference") 
or die(mysql_error());
$resulta=mysql_fetch_row($result);
$getlgu = @mysql_query("select city_municipality_desc from ebpls_city_municipality where city_municipality_code = '$resulta[0]'");
$getlgu = @mysql_fetch_row($getlgu);
$getprov = @mysql_query("select province_desc from ebpls_province where province_code = '$resulta[1]'");
$getprov = @mysql_fetch_row($getprov);

$pdf=new PDF('L','mm','Legal');
$pdf->setLGUinfo($getprov[0],$getlgu[0],'');
$pdf->setDateRange($date_from,$date_to);
$pdf->AddPage();
$pdf->AliasNbPages();

$pdf->SetFont('Arial','B',10);
$pdf->SetY(40);
$pdf->SetX(10);
$pdf->Cell(25,5,'',0,0,'L');
$pdf->SetX(50);
$pdf->Cell(100,5,$criteria,0,1,'L');

$Y_Label_position = 45;
$Y_Table_Position = 55;

$dateprinted = date('Y-m-d');
$pdf->SetFont('Arial','B',8);
$pdf->SetY($Y_Label_position);
$pdf->SetX(5);
$pdf->Cell(340,5,'',0,1,'R');
$pdf->SetFont('Arial','B',6);
$pdf->SetX(5);
$pdf->Cell(10,5,'NO.',1,0,'C');
$pdf->Cell(25,5,'PERMIT NO.',1,0,'C');
$pdf->Cell(30,5,'PERMIT RELEASED DATE',1,0,'C');
$pdf->Cell(50,5,'BUSINESS OWNER',1,0,'C');
$pdf->Cell(50,5,'BUSINESS NAME',1,0,'C');
$pdf->Cell(70,5,'BUSINESS ADDRESS',1,0,'C');
$pdf->Cell(30,5,'DATE OF CLOSURE',1,0,'C');
$pdf->Cell(50,5,'CAUSE / VIOLATION',1,0,'C');

$result = mysql_query ("select distinct (c.business_permit_code) as pid, a.business_name,
        concat(a.business_lot_no, ' ', a.business_street, ' ', f.barangay_desc, ',', ' ',
        g.city_municipality_desc, ',', ' ', h.province_desc, ' ', a.business_zip_code) as bus_add,
        concat(b.owner_first_name, ' ', b.owner_middle_name, ' ', b.owner_last_name) as fulln,
	b.owner_id, a.business_id, a.blacklist, a.black_list_date , a.black_list_reason, c.released_date
        from ebpls_business_enterprise a, ebpls_owner b, ebpls_business_enterprise_permit c,
	tempbusnature d, ebpls_buss_nature e , ebpls_barangay f , ebpls_city_municipality g , ebpls_province h where
        d.active=1 and a.business_barangay_code = f.barangay_code and g.city_municipality_code = a.business_city_code 
        and h.province_code = a.business_province_code and b.owner_id = a.owner_id and a.business_id = c.business_id and
        c.active=1 and a.blacklist = '1' and b.owner_id = d.owner_id and
	a.business_id=d.business_id
	and a.black_list_date between '$date_from 00:00:00' and '$date_to 23:59:59'
        and a.business_barangay_code  like '$brgy_name%'");


	$i = 1;
	$pdf->SetY($Y_Table_Position);
	while ($re=mysql_fetch_assoc($result))
	{
	$pdf->SetX(5);
		$pdf->Cell(10,5,$i,1,0,'C');
		$pdf->Cell(25,5,$re['pid'],1,0,'L');
		$pdf->Cell(30,5,$re['released_date'],1,0,'C');
		$pdf->Cell(50,5,$re['fulln'],1,0,'L');
		$pdf->Cell(50,5,$re['business_name'],1,0,'L');
		$pdf->Cell(70,5,$re['bus_add'],1,0,'L');
		$pdf->Cell(30,5,$re['black_list_date'],1,0,'C');
		$pdf->Cell(50,5,$re['black_list_reason'],1,1,'L');
	$i++;	
	}
	 

$pdf->Cell(270,5,'',0,1,'C');
$pdf->Cell(270,5,'',0,1,'C');

$pdf->SetX(5);
$pdf->SetFont('Arial','B',10);
$pdf->Cell(172,5,'Prepared By :',0,0,'L');
$pdf->Cell(172,5,'Noted By :',0,1,'L');

$pdf->Cell(270,5,'',0,1,'C');
$pdf->Cell(270,5,'',0,1,'C');

$getuser = @mysql_query("select * from ebpls_user where username = '$usernm'") or die(mysql_error());
$getuser = @mysql_fetch_array($getuser);
$getsignatories = @mysql_query("select * from report_signatories where report_file='Blacklisted Business Establishment' and sign_type='3'");
$getsignatories1 = @mysql_fetch_array($getsignatories);
$getsignatories = @mysql_query("select * from global_sign where sign_id='$getsignatories1[sign_id]'");
$getsignatories1 = @mysql_fetch_array($getsignatories);

$pdf->SetX(5);
$pdf->SetFont('Arial','B',10);
$pdf->Cell(172,5,$getuser[firstname].' '.$getuser[lastname],0,0,'L');
$pdf->Cell(172,5,$getsignatories1[gs_name],0,1,'L');
$pdf->SetFont('Arial','B',10);
$pdf->SetX(5);
$datetoday = date('Y - m - d');
$pdf->Cell(172,5,$datetoday,0,0,'L');
$pdf->Cell(172,5,$getsignatories1[gs_pos],0,1,'L');

$pdf->Output();


?>

<!-- ----------------------------------------------------------------
frederick >>> removed this table:

<table width=100% border=0 cellpadding=0 cellspacing=0>
	<tr>
		<td align=center valign="top" rowspan="6">
			<img src='../images/ebpls_logo.jpg' width="100" height="100">
		</td>
		<td align=center>
			<font size=3><b>Republic of the Philippines</b></font>
		</td>
		<tr>
		<td align=center>
			<font size=3><b>Province of <? echo $getprov[0];?></b></font>
		</td>
	</tr>
	<tr>
		<td align=center>
			<font size=3><b>MUNICIPALITY OF <? echo strtoupper($getlgu[0]);?></b></font>
		</td>
	</tr>
	<tr height="20"><td align=center>-o0o-</td></tr>
	<tr>
		<td align=center>
			<font size=5><b>LIST OF BLACKLISTED ESTABLISHMENTS</b></font>
		</td>
	</tr>
	<tr>
		<td align=center>
			<font size=5><b>From <? echo $date_from;?> To <? echo $date_to;?></b></font>
		</td>
	</tr>
	<tr>
		<td align=center colspan=2>
			&nbsp;
		</td>
	</tr>
	<tr>
		<td align=right colspan=2>
			&nbsp;<? echo date('Y-m-d');?>
		</td>
	</tr>
	<tr>
		<td align=left colspan=2>
			<table border=1 cellpadding=0 cellspacing=1>
				<tr>
					<td width=5% align=center><b>No.</b></td>
					<td width=10% align=center><b>Permit Number</b></td>
					<td width=10% align=center><b>Permit Release Date</b></td>
					<td width=15% align=center><b>Owners Name</b></td>
					<td width=15% align=center><b>Business Name</b></td>
					<td width=20% align=center><b>Business Address</b></td>
					<td width=10% align=center><b>Date of Closure</b></td>
					<td width=15% align=center><b>Cause/Violation</b></td>
				</tr>
				<?
				$lrow = 0;
				
				while ($populate = @mysql_fetch_assoc($result))
				{
					$lrow++;
				?>
				<tr>
					<td width=5% align=center><? echo $lrow;?></td>
<!--					<td width=10% align=center><? echo $pid;?></td> -->
					<td width=10% align=center><? echo $populate['pid'];?>
					<td width=10% align=center><? echo $populate['released_date'];?></td>
					<td width=15% align=center><? echo $populate['fulln'];?></td>
					<td width=15% align=center><? echo $populate['business_name'];?></td>
					<td width=20% align=center><? echo $populate['bus_add'];?></td>
					<td width=10% align=center><? echo $populate['black_list_date'];?></td>
					<td width=15% align=center><? echo $populate['black_list_reason'];?></td>
				</tr>
				<?
				}
				?>
			</table>
		</td>
	</tr>
	<tr>
		<td colspan=2>&nbsp;</td>
	</tr>
	<tr width=100%>
		<td align=left colspan=2 width=100%>
			<table border=0 cellpadding=0 cellspacing=0 width=100%>
				<tr>
					<td colspan=4>&nbsp;</td>
				</tr>
				<tr>
					<td width=25%>Prepared By:
					</td>
					<td width=25%>&nbsp;
					</td>
					<td width=25%>Noted By:
					</td>
					<td width=25%>&nbsp;
					</td>
				</tr>
				<tr>
					<td colspan=4>&nbsp;
				</tr>
				<tr>
					<td width=25%>&nbsp;
					</td>
					<td width=25%><? echo $getuser['firstname'].' '.$getuser['lastname'];?>
					</td>
					<td width=25%>&nbsp;
					</td>
					<td width=25%><? echo $getsignatories1['gs_name'];?>
					</td>
				</tr>
				<tr>
					<td width=25%>&nbsp;
					</td>
					<td width=25%>&nbsp;
					</td>
					<td width=25%>&nbsp;
					</td>
					<td width=25%><? echo $getsignatories1['gs_pos'];?>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>
-->
